package ui.panels.primary.games;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.HashMap;

import javax.swing.DefaultListModel;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.LayoutStyle;
import javax.swing.ListModel;

import org.apache.log4j.Logger;

import ui.flowManager.FlowManagerImpl;
import ui.flowManager.MissingData;
import ui.flowManager.expirimentProperties.ExperimentProperties;
import ui.flowManager.expirimentProperties.ExperimentProperties.Missing_Data_Error;
import ui.panels.Panel;
import ui.panels.PanelTypes;
import ui.panels.PanelTypes.PanelType;
import ui.panels.commands.OpenErrorCommand;
import ui.panels.commands.OpenPlayersPanelCommand;
import ui.panels.commands.RunExperimentCommand;
import ui.panels.errors.ErrorFrame;
import ui.panels.errors.ErrorPanel;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
/**
 * @author vladimir && alon
 *
 *	The panel show Games 
 */
/*public class GamesPanel extends Panel{
	
	Logger log = Logger.getLogger(this.getClass());
	
	private JButton 				 next;
	private	JList<String> 			 list;
	private	DefaultListModel<String> listModel;
	private JScrollPane 			 pane;
	
	
	/*** Set a special look for the window*/
	/*{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
		} catch(Exception e) {
			e.printStackTrace();
		}
	}*/
	
	/*
	@Override
	public PanelType getPanelType() {
		// TODO Auto-generated method stub
		return null;
	}
*/
	/*
	@Override
	public void show(ExperimentProperties props) {
		 
		log.debug("show games panel");
			
		try {
			GroupLayout thisLayout = new GroupLayout((JComponent)this);
			this.setLayout(thisLayout);
			setPreferredSize(new Dimension(200, 480));
		

			listModel = new DefaultListModel<String>();
			list = new JList<String>(listModel);
			
			pane = new JScrollPane(list);
			
			{
				next = new JButton();
				next.setText("Next");
			}
			thisLayout.setVerticalGroup(thisLayout.createSequentialGroup()
				.addContainerGap(31, 31)
				.addComponent(next, 0, 42, Short.MAX_VALUE)
				.addGap(50)
				.addComponent(pane, GroupLayout.PREFERRED_SIZE, 321, GroupLayout.PREFERRED_SIZE)
				.addContainerGap(36, 36));
			thisLayout.setHorizontalGroup(thisLayout.createSequentialGroup()
				.addContainerGap(33, 33)
				.addGroup(thisLayout.createParallelGroup()
				    .addGroup(thisLayout.createSequentialGroup()
				        .addComponent(pane, GroupLayout.PREFERRED_SIZE, 127, GroupLayout.PREFERRED_SIZE))
				    .addGroup(thisLayout.createSequentialGroup()
				        .addComponent(next, GroupLayout.PREFERRED_SIZE, 127, GroupLayout.PREFERRED_SIZE)))
				.addContainerGap(40, Short.MAX_VALUE));

			//pane.setPreferredSize(new Dimension(127,207));
			

		} catch (Exception e) {
			e.printStackTrace();
		}

		//add Listeners
		setListeners(props);
		
		//set the games
		setTheTableGameData(props);	
	}
	*/
	
	/**
	 * @param props - ExperimentProperties 
	 */
	/*
	private	void setTheTableGameData(ExperimentProperties props)
	{
		int numOfGames = props.getNumOfGames();
		
		//add the games to the list
		for(int i = 0; i < numOfGames; ++i)
		{
			listModel.add(i, "Game " + (i+1));
		}
		
		
	}
	*/
	
	/**
	 * Set the Listeners
	 * @param props
	 */
	/*
	private void setListeners(ExperimentProperties props)
	{
		// set the list items for double click
		list.addMouseListener(new MouseListener(this, list));
		//set the list items for 'Enter'
		list.addKeyListener(new KeyJList(this, list));
		
		// -------------	set the buttons	-------------------
		
		next.addActionListener(new ActionListener() {
			
			public void actionPerformed(ActionEvent arg0) {
				
				//check that all the games are initialized
				if(isFullData())
				{
					// open the panel of run experiment
					 OpenRunAndSavePanelCommand openRunAndSavePanelCommand = new OpenRunAndSavePanelCommand();
					 openRunAndSavePanelCommand.execute();
				}
				
			}
		});		
	}
	*/
	
	/**
	 * Open the relevant panel of players which in this game
	 * @param jlist
	 * @param gameNumber
	 */
	/*
	public void executeListGame(JList jlist, int gameNumber)
	{		
	     ListModel dlm = jlist.getModel();
	     Object item = dlm.getElementAt(gameNumber - 1);
	     jlist.ensureIndexIsVisible(gameNumber - 1);
	     
	    
	     //execute the OpenPlayersPanelCommand
	     OpenPlayersPanelCommand openPlayersCommand = new OpenPlayersPanelCommand();
	     openPlayersCommand.setGameNumber(gameNumber);
	     openPlayersCommand.execute();  		
	}


	/**
	 * The function Check if all the data was Set
	 * If missing Data open a window with the error message 
	 * @return fullData - boolean
	 */
	/*private boolean isFullData()
	{
		boolean fullData = true;
		
		//take the properties from manager
		ExperimentProperties props = FlowManagerImpl.getInstance().getProps();
		
		//Get the first missing data
		MissingData missingData = props.whatMissing();
		
		// check what is missing and show it to the user
		if(missingData.getErrorType() == Missing_Data_Error.NO_GAMES)
		{
			fullData = false;
			//open error window for the user
			OpenErrorCommand errorCommand = new OpenErrorCommand();
			errorCommand.setMeesage("Have not games in the expiriment");
			errorCommand.execute();		

		}
		else if (missingData.getErrorType() == Missing_Data_Error.GAME_NOT_INITIALIZED)
		{
			fullData = false;
			//open error window for the user
			OpenErrorCommand errorCommand = new OpenErrorCommand();
			errorCommand.setMeesage("Game   " + missingData.getGameNumber() + "  have Not players");
			errorCommand.execute();		
		}
		else if (missingData.getErrorType() == Missing_Data_Error.PLAYER_NOT_INITIALIZED)
		{
			fullData = false;
			//open error window for the user
			
			//ErrorFrame frame = new ErrorFrame();
			//frame.add(new ErrorPanel(frame, "In Game " + missingData.getGameNumber()
			//		+ "  ,Player  "  + missingData.getPlayerNumber() + " Not Initialized"));
			OpenErrorCommand errorCommand = new OpenErrorCommand();
			errorCommand.setMeesage("In Game " + missingData.getGameNumber()
					+ "  ,Player  "  + missingData.getPlayerNumber() + " Not Initialized");
			errorCommand.execute();
		}
		
		return fullData;
	}*/
	
	
	/*
	@Override
	
	public void setFromPropertiesConfig(HashMap<String, String> map) {
		// nothing to set
	}

}*/
